<?php

/**
 * @author christian
 * @copyright 2011
 */

Class MDItineraryEditDraw
{
   
    
    public static $instance;
    
    function __construct()
    {
      
        
    }
    function  DrawHead($action,$name,$method,$NAME){echo "<div id='register-box'>\n";echo "<form action='$action' method='$method' name='$name'>\n";echo "<h2>$NAME</h2>\n";}
    function  DrawFoot(){
        echo "</form>";
        echo "</div>";
      }
        
    function  DrawTextFillBox($title,$items, $maintable, $id)
    {
            
        ?>
               <p>
               <?php 
           
            
    echo "<h3> $title</h3>";

           
               
        $query="select ";
        foreach($items as $campo => $valor){$query=$query.$campo." ,";}
        $query= substr($query,0,strlen($query)-1);
        $query=$query." from " .$maintable. " where idTourTrack=". $id;
         
        $table3=CModelo::getInstance()->getData($query);
      // var_dump($table3);        
       
       
        foreach($table3 as $row =>$colum)
        {
        $tablek=$colum;$k=0;$j=0;
        foreach($tablek as $campo=>$valor)
        {
           foreach($items as $field => $name){
                $items_table[$k]=$name;   
                $k=$k+1;
        }
             
            $select="<label>". $items_table[$j];
            $select = $select."<input type='text' name='$campo' class='general-textarea' value='".$tablek[$campo]."'></br>";
            echo $select."</label>";
            $j=$j+1;
        }     
        }          
               ?>
               
               </p> 
            
        <?php
        
    }
    
    function DrawButton($nombre,$url){
        echo "<input type=button onClick=\"parent.location='$url'\" value='$nombre'><br/>";
        }
        
    function getAnyId($maintable,$mainfield,$mainid,$subfield){
        
        $query="select ". $subfield ." from ". $maintable . " where $mainfield= $mainid";
        $table=CModelo::getInstance()->getData($query);
        
        
         foreach($table as $fila=>$columna){
            $tabla1=$columna;
                foreach($tabla1 as $field=>$value)
                {
                $identificador=$value;
            }
         }
         return $identificador;
     
    }
    
     function HiddenValue($value, $name){
        echo "<input type='hidden' name='$name' value='$value'>"; 
    }
    
   function DrawSelectItinerary($idTour)//especificar los campos que deben de aparecer 
    {
        
        $query = "SELECT `tour_has_track`.`idTourTrack`,`tour_has_track`.`DateBegTrack` FROM tour_has_track LEFT JOIN `viv`.`track` ON `tour_has_track`.`TRACK_idTrack` = `track`.`idTrack` WHERE(( TOUR_idTour = $idTour)) order by `idTourTrack` ASC";
        $table2=CModelo::getInstance()->getData($query);
 
        ?>
       <select name="type" class="input_pulldown">
       <option value="NULL" selected="selected" style="display:none;"></option>
       
        <?php
        foreach($table2 as $row =>$colum)
        {
        $tabla=$colum;$select="";$i=0;
        foreach($tabla as $campo=>$valor)
        {
            if($i<=0){$select=$select."<option value=".$valor."> ($valor) ";}
            else{$select=$select.$tabla[$campo];}
            $i=$i+1;
        }
        echo $select."</option>\n";
        }
        ?>
        </select>       
      
        
    
    <?php
    }
    function DrawRadioButton($items,$name)
    {
      
       
      foreach($items as $id => $valor)
                    {
                        echo "<label>".$id."<input type='radio' class=\"input-radio\" name='$name' value='$valor'>"."</label>\n";
                        
                    }   
    }
    
 
    
    function DrawSubmmit($nombre){echo "<input class='submit_button' type='submit' name=$nombre value='$nombre'>";}
    
    public static function getInstance()
	{
		//echo "<div id=register-box>";
        if(self::$instance==null)
		  self::$instance=new MDItineraryEditDraw();
	//   echo "</div>";	  
		return  self::$instance;
	   
    
    }	
    
    
}

?>